package com.gali.medical.service.impl;

import com.gali.medical.mapper.CheckItemMapper;
import com.gali.medical.pojo.CheckItem;
import com.gali.medical.service.CheckItemService;
import com.gali.medical.utils.MessageConstant;
import com.gali.medical.utils.PageResult;
import com.gali.medical.utils.QueryPageBean;
import com.gali.medical.utils.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * @author gali
 * @description:
 * @date 2022/6/25 10:52
 */
@Service
@org.springframework.stereotype.Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * 增加项目组
     * @param checkItem
     * @return
     */
    @Override
    public Result addCheckItem(CheckItem checkItem) {
        boolean flag=false;
        flag=checkItemMapper.insertCheckItem(checkItem)>0;
        if (flag){
            return new Result(flag, MessageConstant.ADD_CHECKITEM_SUCCESS);
        }else {
            return new Result(flag, MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findItemInfo(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<CheckItem> list=null;
        if (queryPageBean.getQueryString()!=null&&queryPageBean.getQueryString().length()>0){
            list=checkItemMapper.findLikeItemInfo(queryPageBean.getQueryString());
        }else {
            list=checkItemMapper.findItemInfo();
        }
        PageInfo<CheckItem> checkItemPageInfo = new PageInfo<>(list);
        return new PageResult(checkItemPageInfo.getTotal(),checkItemPageInfo.getList());
    }

    /**
     * 删除检查组
     * @param id
     * @return
     */
    @Override
    public Result deleteItem(Integer id) {
        boolean flag=false;
        flag=checkItemMapper.deleteItem(id)>0;
        if (flag){
            return new Result(flag,MessageConstant.DELETE_CHECKITEM_SUCCESS);
        }else {
            return new Result(flag,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
    }

    /**
     * 更新项目组
     * @param checkItem
     * @return
     */
    @Override
    public Result updateItem(CheckItem checkItem) {
        boolean flag=false;
        flag=checkItemMapper.updateItem(checkItem)>0;
        if (flag){
            return new Result(flag,MessageConstant.EDIT_CHECKITEM_SUCCESS);
        }else {
            return new Result(flag,MessageConstant.EDIT_CHECKITEM_FAIL);
        }
    }

    /**
     * 根据id查询项目组
     * @param id
     * @return
     */
    @Override
    public Result findOneItem(Integer id) {
        CheckItem checkItem=checkItemMapper.selectOneItem(id);
        if (checkItem!=null){
            return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkItem);
        }else {
            return new Result(false,MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }
}
